package top.cptr.so.aliyundomainserver.service.impl;

import com.aliyun.alidns20150109.Client;
import com.aliyun.alidns20150109.models.DescribeDomainsRequest;
import com.aliyun.alidns20150109.models.DescribeDomainsResponse;
import com.aliyun.alidns20150109.models.DescribeDomainsResponseBody;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import top.cptr.so.aliyundomainserver.aliyunSDKUtils.ClientBeanFactory;
import top.cptr.so.aliyundomainserver.aliyunSDKUtils.exception.CreateClientException;
import top.cptr.so.aliyundomainserver.aliyunSDKUtils.exception.RequestInterfaceException;
import top.cptr.so.aliyundomainserver.service.DomainMange;

@Service
public class DomainMangeImpl implements DomainMange {
    @Autowired
    ClientBeanFactory clientBeanFactory;

    @Override
    public DescribeDomainsResponseBody describeDomains(String token,DescribeDomainsRequest requestParam) throws CreateClientException, RequestInterfaceException {
        Client client = clientBeanFactory.createClient(token);
        DescribeDomainsResponseBody body;
        try {
            DescribeDomainsResponse domainsResponse = client.describeDomains(requestParam);
            body=domainsResponse.getBody();
        } catch (Exception e) {
            throw new RequestInterfaceException("请求错误",e);
        }
        return body;
    }
}
